//
//  Game1TableViewCell.m
//  GOGOTravel
//
//  Created by dllo on 16/2/1.
//  Copyright © 2016年 果果. All rights reserved.
//

#import "Game1TableViewCell.h"






@implementation Game1TableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    
        
    }
    return self;
}

- (void)setModel:(Game *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    _BackImage.layer.borderWidth = 2;
    _BackImage.layer.borderColor = [UIColor orangeColor].CGColor;
  
    
    _headImage.layer.cornerRadius = 40;
    _headImage.layer.masksToBounds = YES;
    _headImage.layer.borderColor = [UIColor whiteColor].CGColor;
    _headImage.layer.borderWidth = 2;
    
    _button.layer.cornerRadius = 40;
    _button.layer.masksToBounds = YES;
    
    
    [self setValues];
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
  
}


- (void)setValues{
    
    _BackImage.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    
    [_BackImage addGestureRecognizer:tap];
    
    [tap release];
    
    
    
    _BackImage.image = [UIImage imageNamed:@"c9ae268f5276a82f43c7c62330fc40f3.jpg"];
    
    _PlayImage.image = [UIImage imageNamed:@"iconfont-bofang.png"];
    //user的字典
    NSDictionary *user = _model.user;
    NSString *url = user[@"avatar_l"];
    [_headImage sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
    
    NSString *name = user[@"name"];
    _nameLabel.text = [NSString stringWithFormat:@"by %@", name];
    
    _titleLabel.text = _model.name;
    _titleLabel.numberOfLines = 2;
    
    _dateLabel.text = _model.first_day;
    _dayLabel.text = [_model.day_count stringValue];
    
    //路程
    
    NSString *str = [_model.mileage stringValue];
    if (str.length >=5) {
        
        NSString *str1 = [str substringToIndex:5];
        _liChengLabel.text = str1;
    }
    _likeNumberLabel.text = [_model.recommendations stringValue];
}

- (void)awakeFromNib {
    // Initialization code
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"yeJianMoShi"] isEqualToString:@"isDay"]) {
        self.backgroundColor = DAYCOLOR;
    }else{
        self.backgroundColor = NIGHTCOLOR;
    }
    
    


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"yeJianMoShi" object:nil];
}
- (void)changeColor:(NSNotification *)notification{
    
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"yeJianMoShi"]isEqualToString:@"isNight"]) {
        self.backgroundColor = NIGHTCOLOR;
    }else{
        
        self.backgroundColor = DAYCOLOR;
    }
    
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc {
     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeColor" object:nil];
    [_BackImage release];
    [_PlayImage release];
    [_headImage release];
    [_nameLabel release];
    [_titleLabel release];
    [_view1 release];
    [_dateLabel release];
    [_LichengLabel release];
    [_likeLanel release];
    [_likeNumberLabel release];
    [_liChengLabel release];
    [_dayLabel release];
    [_button release];
    [_boFangButton release];
    [super dealloc];
}
- (IBAction)BUTTONaCTION:(id)sender {
    
    NSLog(@"我是button");
}

- (IBAction)BoFangButton:(id)sender {
    
    NSLog(@"播放button");
     [self.delegate jumpToMap:_model.start_point];
    
}










@end
